from flask import Blueprint, request
from models.person import Person

person_blueprint = Blueprint('person_bp', __name__, url_prefix='/')


@person_blueprint.route('/persons', methods=['GET'])
def get_all_persons():
    return Person.get_persons()

@person_blueprint.route('/persons', methods=['POST'])
def add_person():
    # 获取请求体中的 JSON 数据
    data = request.get_json()

    # 提取传入的数据
    personId = data.get('personId')
    name = data.get('name')
    age = data.get('age')
    email = data.get('email')
    return Person.add_person(personId, name, age, email)

@person_blueprint.route('/persons/<personId>', methods=['PUT'])
def update_person(personId):
    # 获取请求体中的 JSON 数据
    data = request.get_json()

    # 提取传入的数据
    personId = data.get('personId')
    name = data.get('name')
    age = data.get('age')
    email = data.get('email')
    return Person.update_person(personId,name, age, email)

@person_blueprint.route('/persons/<personId>', methods=['DELETE'])
def delete_person(personId):
    return Person.delete_person(personId)
